import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'CustomDialog.dart';
import 'MyCustomLoadingDialog.dart';

class WDialog extends StatefulWidget {
  @override
  _WDialogState createState() => _WDialogState();
}

class _WDialogState extends State<WDialog> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("dialog"),
        centerTitle: true,
      ),
      body: Container(
        child: Align(
          child: Column(
            children: <Widget>[
              OutlineButton(
                onPressed: () {
                  showDialog(
                      context: context, builder: (ctx) => _buildAlertDialog());
                },
                child: Text("show AlertDialog"),
              ),
              OutlineButton(
                onPressed: () {
                  showCupertinoDialog(
                      context: context,
                      builder: (context) {
                        return CupertinoAlertDialog(
                          title: Text('提示'),
                          content: Text('确认删除吗？'),
                          actions: <Widget>[
                            CupertinoDialogAction(
                              child: Text('取消'),
                              onPressed: () {
                                Navigator.of(context).pop();
                              },
                            ),
                            CupertinoDialogAction(
                              child: Text('确认'),
                              onPressed: () {
                                Navigator.of(context).pop();
                              },
                            ),
                          ],
                        );
                      });
                },
                child: Text("show ios CupertinoAlertDialog"),
              ),
              OutlineButton(
                onPressed: () {
                  showMyDialogWithColumn(context);
                },
                child: Text("自定义列表Dialog"),
              ),
              OutlineButton(
                onPressed: () {
                  showDialog(
                      context: context,
                      barrierDismissible: true,
                      builder: (context) {
                        return new MyCustomLoadingDialog();
                      });
                },
                child: Text("自定义AlertDialog"),
              ),
              RaisedButton(
                child: Text("showDialog"),
                onPressed: () {
                  showDialog(
                      context: context,
                      barrierDismissible: true,
                      builder: (BuildContext context) {
//                        //带有标题的Dialog
//                        return CustomDialog(
//                          title: '这是一个标题',
//                          content: '这里是弹窗的提示内容',
//                        );
//                      //自定义确定按钮颜色
//                        return CustomDialog(
//                            title: '这是一个标题',
//                            content: '这里是弹窗的提示内容',
//                            isCancel: true,
//                            confirmColor: Colors.green[400]
//                        );
                        //Dialog按钮点击回调监听
                        return CustomDialog(
                          title: '这是一个标题',
                          content: '这里是弹窗的提示内容',
                          confirmCallback: () {
                            print('-----------点击了确定按钮');
                          },
                        );
                      });
                },
              )
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildAlertDialog() {
    return AlertDialog(
      title: Text('提示'),
      content: Text('确认删除吗？'),
      actions: <Widget>[
        FlatButton(
          child: Text('取消'),
          onPressed: () {
            Navigator.of(context).pop();
          },
        ),
        FlatButton(
          child: Text('确认'),
          onPressed: () {
            Navigator.of(context).pop();
          },
        ),
      ],
    );
  }

  void showMyDialogWithColumn(BuildContext context) {
    showDialog(
        context: context,
        builder: (context) {
          return new AlertDialog(
            title: new Text("title"),
            content: new SingleChildScrollView(
              child: new Column(
                children: <Widget>[
                  new SizedBox(
                    height: 100,
                    child: new Text("1"),
                  ),
                  new SizedBox(
                    height: 100,
                    child: new Text("1"),
                  ),
                  new SizedBox(
                    height: 100,
                    child: new Text("1"),
                  ),
                  new SizedBox(
                    height: 100,
                    child: new Text("1"),
                  ),
                  new SizedBox(
                    height: 100,
                    child: new Text("1"),
                  ),
                  new SizedBox(
                    height: 100,
                    child: new Text("1"),
                  ),
                  new SizedBox(
                    height: 100,
                    child: new Text("1"),
                  ),
                  new SizedBox(
                    height: 100,
                    child: new Text("1"),
                  ),
                  new SizedBox(
                    height: 100,
                    child: new Text("1"),
                  ),
                  new SizedBox(
                    height: 100,
                    child: new Text("1"),
                  ),
                  new SizedBox(
                    height: 100,
                    child: new Text("1"),
                  ),
                  new SizedBox(
                    height: 100,
                    child: new Text("1"),
                  ),
                ],
              ),
            ),
            actions: <Widget>[
              new FlatButton(
                onPressed: () {},
                child: new Text("确认"),
              ),
              new FlatButton(
                onPressed: () {},
                child: new Text("取消"),
              ),
            ],
          );
        });
  }
}
